package cn.kgc.house.service;

import cn.kgc.house.mapper.HouseInfoMapper;
import cn.kgc.house.mapper.HouseTypeMapper;
import cn.kgc.house.pojo.HouseInfo;
import cn.kgc.house.pojo.HouseInfoExample;
import cn.kgc.house.pojo.HouseType;
import cn.kgc.house.util.Constant;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HouserInfoServiceImpl implements HouserInfoService {
    @Resource
    HouseTypeMapper houseTypeMapper;
    @Resource
    HouseInfoMapper houseInfoMapper;


    @Override
    public PageInfo<HouseInfo> selectAll(Integer typeid, Integer pageNo) {
        PageHelper.startPage(pageNo, Constant.pageSize);
        HouseInfoExample example = new HouseInfoExample();
        if (typeid != null && typeid != 0) {
            example.createCriteria().andTypeidEqualTo(typeid);
        }
        List<HouseInfo> houseInfos = houseInfoMapper.selectByExample(example);
        PageInfo<HouseInfo> pageInfo = new PageInfo<>(houseInfos);
        return pageInfo;
    }

    @Override
    public HouseInfo selectById(Integer houseid) {
        return houseInfoMapper.selectByPrimaryKey(houseid);
    }

    @Override
    public int add(HouseInfo houseInfo) {
        return houseInfoMapper.insert(houseInfo);
    }

    @Override
    public int update(HouseInfo houseInfo) {
        return houseInfoMapper.updateByPrimaryKey(houseInfo);
    }

    @Override
    public int delete(Integer houseid) {
        return houseInfoMapper.deleteByPrimaryKey(houseid);
    }
}
